export const useAppStore = defineStore(
    'app',
    {
        state: () => ({
            sidebar: {
                opened: useLocalStorage('sidebarStatus',true).value,
                hide: false,
                withoutAnimation: false,
                isClickCollapse: false
            },
            device: 'desktop',
            // 浏览器窗口的可视区域大小
            viewportSize: {
                width: document.documentElement.clientWidth,
                height: document.documentElement.clientHeight
            }
        }),
        actions: {
            // 开关侧边栏
            TOGGLE_SIDEBAR(opened, resize) {
                const sidebarStatus = useLocalStorage('sidebarStatus',true)
                if (opened && resize) {
                    this.sidebar.withoutAnimation = true
                    this.sidebar.opened = true
                    sidebarStatus.value = true
                } else if (!opened && resize) {
                    this.sidebar.withoutAnimation = true
                    this.sidebar.opened = false
                    sidebarStatus.value = false
                } else if (!opened && !resize) {
                    this.sidebar.withoutAnimation = false
                    this.sidebar.opened = !this.sidebar.opened
                    this.sidebar.isClickCollapse = !this.sidebar.opened
                    sidebarStatus.value = this.sidebar.opened
                }
            },
            // 开关侧边栏
            async toggleSideBar(opened, resize) {
                await this.TOGGLE_SIDEBAR(opened, resize);
            },
            // 修改当前设备信息
            toggleDevice(device) {
                this.device = device
            },
            // 是移动端吗?
            isMobile(){
                return this.device === 'mobile'
            }
        }
    })
